package br.net.woodstock.tickettoride.web.seam.manager;

import javax.faces.event.FacesEvent;

import org.jboss.seam.ScopeType;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.core.Conversation;
import org.richfaces.event.UploadEvent;

import br.net.woodstock.tickettoride.api.manager.ApplicationService;
import br.net.woodstock.tickettoride.api.manager.CertificateService;
import br.net.woodstock.tickettoride.web.jsf.manager.common.AbstractCertificateBean;

@Name("certificateBean")
@Scope(ScopeType.CONVERSATION)
public class CertificateBean extends AbstractCertificateBean {

	private static final long	serialVersionUID	= -334653897238184433L;

	@In("#{applicationService}")
	private ApplicationService	applicationService;

	@In("#{certificateService}")
	private CertificateService	certificateService;

	@In
	private Conversation		conversation;

	@Override
	public ApplicationService getApplicationService() {
		return this.applicationService;
	}

	@Override
	public CertificateService getCertificateService() {
		return this.certificateService;
	}

	@Override
	protected void onStart() {
		this.conversation.begin();
	}

	@Override
	protected void onEnd() {
		this.conversation.end(true);
	}

	@Override
	protected byte[] getBytesFromUpload(final FacesEvent event) {
		UploadEvent e = (UploadEvent) event;
		return e.getUploadItem().getData();
	}

}
